package ebj.common.java8.collection;
import java.util.HashSet;
import java.util.Set;

public class 测试交并差集 {

    public static void main(String[] args) {
        Set<Integer> result = new MyCustomSet<Integer>();
        Set<Integer> set1 = new HashSet<Integer>(){{
            add(1);
            add(3);
            add(5);
        }};

        Set<Integer> set2 = new HashSet<Integer>(){{
            add(1);
            add(2);
            add(3);
        }};

        result.clear();
        result.addAll(set1);
        result.retainAll(set2);
        System.out.println("交集："+ result);
        System.out.println("交集："+ new MyCustomSet<Integer>().intersection(set1, set2));

        result.clear();
        result.addAll(set1);
        result.removeAll(set2);
        System.out.println("差集："+ result);
        System.out.println("差集："+ new MyCustomSet<Integer>().setDifference(set1, set2));

        result.clear();
        result.addAll(set1);
        result.addAll(set2);
        System.out.println("并集："+ result);
        System.out.println("并集："+ new MyCustomSet<Integer>().union(set1, set2));

    }

}